package com.fast.fastenjoy.base.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang.StringUtils;

import com.fast.fastenjoy.base.utils.BeanExUtils;

/**
 * Hibernate ORM 映射父类
 * @author chenliaohua
 *
 */
@MappedSuperclass
public abstract class BaseDomain extends JDomain implements Serializable{
	
	private static final long serialVersionUID = -3061098734075004006L;

	public static final String FIELD_ID = "id";
	public static final String FIELD_CREATE_BY = "createBy";
	public static final String FIELD_CREATE_TIME = "createTime";
	public static final String FIELD_UPDATE_BY = "updateBy";
	public static final String FIELD_UPDATE_TIME = "updateTime";
	
	protected String createBy;
	
	protected Date createTime;
	
	protected String updateBy;
	
	protected Date updateTime;

	/**
	 * 获取主键ID
	 * @param obj
	 * @param fieldIdName
	 * @return
	 */
	public static Serializable getId(Object obj, String fieldIdName){
		
		if(obj == null){
			
			return null;
		}
		
		String idKek = FIELD_ID;
		
		if(StringUtils.isNotEmpty(fieldIdName)){
			idKek = fieldIdName;
		}
		
		Serializable s = null;
		
		try{
			s = BeanExUtils.getProperty(obj, idKek);
		}catch(Exception e){
		}
		
		return s;
	}
	
	@Column
	public String getCreateBy() {
		return createBy;
	}

	public void setCreateBy(String createBy) {
		this.createBy = createBy;
	}

	@Column
	@Temporal(TemporalType.TIMESTAMP)
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column
	public String getUpdateBy() {
		return updateBy;
	}

	public void setUpdateBy(String updateBy) {
		this.updateBy = updateBy;
	}

	@Column
	@Temporal(TemporalType.TIMESTAMP)
	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

}
